/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package htmlunit.code;

import com.gargoylesoftware.htmlunit.BrowserVersion;
import com.gargoylesoftware.htmlunit.WebClient;
import com.gargoylesoftware.htmlunit.html.HtmlPage;
import java.io.UnsupportedEncodingException;
import java.net.CookieManager;
import java.net.CookiePolicy;
import java.net.URLDecoder;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author TiTa
 */
public class ket_noi_url {

    // DomElement doc;
  
     public HtmlPage ketnoi(String url){
        HtmlPage  page = null;
     try{
         
       java.util.logging.Logger.getLogger("com.gargoylesoftware.htmlunit").setLevel(java.util.logging.Level.OFF);
         java.util.logging.Logger.getLogger("org.apache.http").setLevel(java.util.logging.Level.OFF);
     //--!end warning
        final WebClient webClient = new WebClient(BrowserVersion.CHROME);
         webClient.waitForBackgroundJavaScript(5000);
        webClient.getOptions().setUseInsecureSSL(true);
         
        webClient.getOptions().setJavaScriptEnabled(false);
    //--------------------them moi zo
       // webClient.getOptions().setAppletEnabled(true);
        webClient.getOptions().setCssEnabled(true);
    //    AjaxController ajaxController = new AjaxController();
CookieManager cookieManager = new CookieManager();
cookieManager.setCookiePolicy(CookiePolicy.ACCEPT_ALL);
       page = webClient.getPage(url);
   
       

        System.out.println("kết nối thành công với"+"\n"+ URLDecoder.decode(url, "UTF-8")+ "\n");
       
        
        webClient.closeAllWindows();
        
     }catch(Exception ex){
            try {
                System.out.println("không vào được địa chỉ "+"\n"+ URLDecoder.decode(url, "UTF-8")+" \n");
            } catch (UnsupportedEncodingException ex1) {
                Logger.getLogger(ket_noi_url.class.getName()).log(Level.SEVERE, null, ex1);
            }
     }
         
           
         return page;
     }
     
    
   //  public static void main(String[] args){
  /*   ket_noi_url ffg=new ket_noi_url();

          HtmlPage page= ffg.ketnoi("https://www.google.com.vn/#q=site:facebook.com+cafe&start=90");
          final HtmlTable link_footer_trang10= (HtmlTable) page.getByXPath("//table[@id='nav']").get(0);
     
         String link_foot10=link_footer_trang10.getElementsByTagName("a").get(11).getTextContent();//so trang
    String link10=link_footer_trang10.getElementsByTagName("a").get(11).getAttribute("href");
     System.out.println(link_foot10+"\n"+link10+"\n");
     * */
   // }


}
